package models

import (
	"gorm.io/gorm"
	"order_srv/basic/config"
	"time"
)

// 改派表
type Reassign struct {
	Id           uint64         `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	OrderId      uint64         `gorm:"column:order_id;type:bigint UNSIGNED;comment:订单id;not null;" json:"order_id"`                          // 订单id
	UserId       uint64         `gorm:"column:user_id;type:bigint UNSIGNED;comment:操作人id;not null;" json:"user_id"`                           // 操作人id
	TakingDriver uint64         `gorm:"column:taking_driver;type:bigint UNSIGNED;comment:接单司机id;not null;" json:"taking_driver"`              // 接单司机id
	AssignDriver uint64         `gorm:"column:assign_driver;type:bigint UNSIGNED;comment:改派司机id;not null;" json:"assign_driver"`              // 改派司机id
	Reason       string         `gorm:"column:reason;type:varchar(255);comment:改派原因;not null;" json:"reason"`                                 // 改派原因
	Status       uint8          `gorm:"column:status;type:tinyint UNSIGNED;comment:审核状态 1-待审核 2-已通过 3-未通过;not null;default:1;" json:"status"` // 审核状态 1-待审核 2-已通过 3-未通过
	CreatedAt    time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt    time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt    gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (r *Reassign) TableName() string {
	return "reassign"
}

// 改派创建
func (r *Reassign) ReassignCreate() error {
	return config.DB.Create(&r).Error
}

// id查询改派详情
func (r *Reassign) GetReassignInfo(Id int) error {
	return config.DB.Where("id = ?", Id).Limit(1).Find(&r).Error
}

// 更新改派状态
func (r *Reassign) UpdateReassignStatus(Id int) error {
	return config.DB.Model(&r).Where("id = ?", Id).Update("status", r.Status).Error
}
